import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return {
    plugins: [vue()],
    // base:"monthEval",
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      host: '127.0.0.1',
      proxy: {
        '/api': {
          target: env.VITE_API_BASE_URL, // 将请求代理到的目标地址
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '') // 将请求路径重写，去掉开头的 '/api'
        }
      },
    },
  };
});